<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class Adv extends CI_Controller {
	var $eData = '';
	function __construct() {
		parent::__construct ();
		$this->thor->loginstate ();
	}
	
	function index() {
		
		$eCID = ( int ) $this->input->get ( 'cid' );
		
		$this->db->where ( 'cid', $eCID ); //首页广告
		

		$this->db->order_by ( 'sort', 'asc' );
		$this->db->order_by ( 'id', 'desc' );
		$this->db->where ( 'cid', $eCID );
		$this->eData ['advList'] = $this->db->get ( 'adv' )->result_array ();
		
		$this->eData ['eCID'] = $eCID;
		
		$this->load->view ( 'mang/adv', $this->eData );
	}
	
	function action() {
		$eCID = ( int ) $this->input->get ( 'cid' );
		
		
		$eSort = $this->input->post ( 'sort' );
		$eUrl = $this->input->post ( 'url' );
		$eLink = $this->input->post ( 'link' );
		$eTitle = $this->input->post ( 'title' );
		$this->db->where ( 'cid', $eCID );
		$this->db->delete('adv');
		foreach ( $eUrl as $i => $item ) {
			$inData = array(
				'cid' => $eCID,
				'image'=>$item,
				'link'=>$eLink [$i],
				'title'=>$eTitle [$i],
				'sort'=>$eSort [$i],
				'createtime'=>time()
			);
			$this->db->insert('adv', $inData);
		}
		
		
		
		
		echo '<script type="text/javascript">
			alert("保存成功.");
			window.location.href = "' . site_url ( 'mang/adv?cid='.$eCID ) . '";
			</script>';
		exit ();
	}

}